//-------------------------------------------------------------------------------
//!\file	Timer.h
// \author	Pete Kugler and John Jensen
// \date	Wednesday, October 9, 2004
// \par		license
//			All content (c) 2005, DigiPen (USA) Corporation, all rights reserved.
// \brief	This is the header file for the CTimer class
//-------------------------------------------------------------------------------
#ifndef TIMER_H
#define TIMER_H

#include <windows.h> // LARGE_INTEGER union
#undef GetCurrentTime // Gets rid of #define GetCurrentTime() GetTickCount()

#pragma comment(lib, "winmm.lib") // timer stuff

/*!===============================================================================
\class	CTimer
\brief	This class is used to create a timer to be used by the game application.
		The class will first try to initialize itself with the performance timer,
		however if that fails, then the default multimedia timer is used.

		To use:
			- Create a CTimer object.
			- Call the Update() function and then either refer to GetCurrentTime()
				or GetFrameTime().
			- GetFrameTime() will return the time that has elapsed since call 1 of
				Update() and call 2 of Update():
				\code
					CTimer timer;							\n
					Sleep(100);								\n
					cout << timer.GetFrameTime(); // 0		\n
					timer.Update();							\n
					cout << timer.GetFrameTime(); // ~.100  \n
					Sleep(1000);							\n
					cout << timer.GetFrameTime(); // ~.100  \n
					timer.Update();							\n
					cout << timer.GetFrameTime(); // ~1.000 \n
				\endcode
				Please note that Update() *must* be called before calling either
				GetFrameTime() or GetCurrentTime()
			- GetCurrentTime() returns the time that has elapsed, in seconds,
				since the creation of the object or the last time Reset() was
				called.
*///==============================================================================
class CTimer
{
public:
	CTimer(bool bDefMM = false);
	~CTimer();

	void Reset();
	void Update();	// each game frame

	// data access
	double GetCurrentTime() { return dCurrentTime_; }
	float GetFrameTime()    { return fFrameTime_;   } 

	void SetTime(double fTime);

private:
	void Init(bool bDefMM);

	typedef double (CTimer::* TimeUpdateFunc) ();	 // pointer to a function
	TimeUpdateFunc pfnUpdate_;

	double dBaseTime_;
	double dLastTime_;
	double fSecsPerTick_;

	double dCurrentTime_;
	float  fFrameTime_;

	LARGE_INTEGER nTimerStart_;
	LARGE_INTEGER nCurrentTime_;

	// use to bind with pfnUpdate_	
	double GetPerformanceCounterTime();	// performance timer
	double GetMMTime();					// default multimedia timer
};

#endif

